<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

	<meta charset="UTF-8">
	<title>Insert title here</title>
	<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
	<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="../../css/global.css" media="all" />
</head>
<body>
<div class="panel-page">
	<div class="top-box">
		巡察问题审核
	</div>
	<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
		<!--<div class="title-container">
			督办录入事项
		</div>-->
		<form class="layui-form form-container" lay-filter="scoreRuleForm" style="width: 1100px;margin: 0 auto" action="">
			<div class="layui-form-item">
				<label class="layui-form-label">问题项</label>
				<div class="layui-input-block">
					<input type="text" name="question" required  lay-verify="required" readonly aria-readonly="true" placeholder="请输入标题" id="question" autocomplete="off" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">

				<!--<div class="layui-inline">
					<label class="layui-form-label">巡查日期</label>
					<div class="layui-input-inline">
						<input type="text" id="startPatrolTime" name="startPatrolTime"
							   readonly="" class="layui-input" placeholder="请选择">
					</div>
				</div>-->

				<div class="layui-inline">
					<label class="layui-form-label">巡察单位</label>
					<div class="layui-input-inline" readonly aria-readonly="true">
						<select name="branch" id="branch" lay-verify="required" lay-filter="xmFilter">

						</select>
					</div>
				</div>

				<!--<div class="layui-inline">
					<label class="layui-form-label">部门</label>
					<div class="layui-input-inline">
						<select name="branchb" id="branchb" lay-verify="required" lay-filter="xmFilter">
						</select>
					</div>
				</div>-->
				<div class="layui-inline">
					<label class="layui-form-label" readonly aria-readonly="true">督察形式</label>
					<div class="layui-input-inline">
						<select name="overseeForm" id="overseeForm" lay-verify="required" lay-filter="xmFilter">

						</select>
					</div>
				</div>
			</div>

			<div class="layui-form-item">

				<div class="layui-inline">
					<label class="layui-form-label" readonly aria-readonly="true" >问题类别</label>
					<div class="layui-input-inline">
						<select name="questionType" id="questionType" lay-verify="required" lay-filter="xmFilter">

						</select>
					</div>
				</div>

				<div class="layui-inline">
					<label class="layui-form-label" readonly aria-readonly="true" >问题关键字</label>
					<div class="layui-input-inline">
						<select name="questionKeyword" id="questionKeyword" lay-verify="required" lay-filter="xmFilter">

						</select>
					</div>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label" readonly aria-readonly="true" >问题描述</label>
				<div class="layui-input-block" >
					<textarea placeholder="请输入内容" id="questionDetail" name="questionDetail" class="layui-textarea"></textarea>
				</div>
			</div>



			<div class="layui-form-item">
				<label class="layui-form-label">审批意见</label>
				<div class="layui-input-block">
					<textarea placeholder="审批意见" id="remark" name="remark" class="layui-textarea"></textarea>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">

					<button type="button" class="layui-btn" lay-filter="saveBtn">同意</button>
					<button type="button" class="layui-btn" lay-filter="saveBtn2">不同意</button>

					<button type="button" class="layui-btn layui-btn-sm" id="test4"><i class="layui-icon"></i>查看附件</button>
				</div>
			</div>
		</form>
		<div class="title-container">
			审核记录
			<i class="layui-icon layui-icon-up"></i>
		</div>
		<div class="widget-body no-padding">
			<table id="records" class="table table-striped table-bordered table-hover" style="width:100%">
				<thead>
				<tr>
				</tr>
				<tr>
					<th style="display: none">id</th>
					<th>审核人</th>
					<th>审批时间</th>
					<th>审核状态</th>
					<th>审批意见</th>
				</tr>
				</thead>
				<tbody>
				</tbody>
			</table>
		</div>

	</div>
</div>


</body>
</html>

<script type="text/javascript" src="../../js/libs/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<!--<script src="../../layui/laydate/laydate.js"></script>-->
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript">
	//获取url后的参数值
	function getUrlParam(key) {
		var href = window.location.href;
		var url = href.split("?");
		if(url.length <= 1){
			return "";
		}
		var params = url[1].split("&");

		for(var i=0; i<params.length; i++){
			var param = params[i].split("=");
			if(key == param[0]){
				return param[1];
			}
		}
	}
	//刷新表单
	function renderForm() {
		layui.use('form', function() {
			var form = layui.form; //高版本建议把括号去掉，有的低版本，需要加()
			form.render();
		});
	}
	// 数据回显
	layui.use(['layer','form'], function(){
		var layer = layui.layer;
		var form = layui.form;
		var id = getUrlParam("id");
		if(id > 0){
			$.ajax({
				type : 'get',
				url : '/mOverseeQuestions/'+id,
				async : false,
				success : function(data) {
					console.log(data)
					$("#question").val(data.question);
					$("#questionId").val(data.questionId);
					$("#questionDetail").val(data.questionDetail);
					$("#remark").val(data.remark);
					$("#questionType").val(data.questionType);


					$("#branch").append("<option value="+0+">"+data.brancha+"</option>");
					$("#overseeForm").append("<option value="+1+">"+data.overseeForm+"</option>");
					renderForm();
					$("#startPatrolTime").val(data.startPatrolTime);

					/*form.val('scoreRuleForm',{

						"question": data.question,
						"questionId": data.questionId,
						"questionType": data.questionType,
						"questionKeyword": data.questionKeyword,
						"questionDetail": data.questionDetail,
						"remark": data.remark,
						"overseeForm": data.overseeForm,
						"branch": data.brancha,
						"branchb": data.branchb,
						"startPatrolTime": data.startPatrolTime,
					})*/




				}

			});
		}

	});


	// 区域展开伸缩
	$('.title-container .layui-icon').click(function () {
		var thisIcon = $(this);
		if(thisIcon.hasClass("layui-icon-up"))
		{
			thisIcon.removeClass("layui-icon-up").addClass("layui-icon-down");
			thisIcon.parent().next().slideUp(200)
		}
		else
		{
			thisIcon.removeClass("layui-icon-down").addClass("layui-icon-up");
			thisIcon.parent().next().slideDown(200)
		}
	})

	function PanelInit() {
		recordsInit()
		progressInit()
	}

	// 表格初始化数据
	var records;
	function recordsInit(){
		records =
				$('#records').DataTable({
					"searching": false,
					"processing": false,
					"serverSide" : true,
					"ordering": false,
					"language": {
						"url": "/js/plugin/datatables/Chinese.lang"
					},
					"ajax": {
						"url" : "/questionRecords",
						"type":"get",
						"data":function(d){
							d.question = $('#question').val();
							d.questionKeyword = $("#questionKeyword option:selected").text();
							d.questionType = $("#questionType option:selected").text();
							d.questionStatus = $("#questionStatus option:selected").text();
							d.brancha = $("#brancha option:selected").text();
							d.branchb = $("#branchb option:selected").text();
						},
						"error":function(xhr, textStatus, errorThrown){
							var msg = xhr.responseText;
							console.log(msg);
							var response = JSON.parse(msg);
							var code = response.code;
							var message = response.message;
							if (code == 400) {
								layer.msg(message);
							} else if (code == 401) {
								localStorage.removeItem("token");
								layer.msg("token过期，请先登录", {shift: -1, time: 1000}, function(){
									location.href = '/login.html';
								});
							} else if (code == 403) {
								console.log("未授权:" + message);
								layer.msg('未授权');
							} else if (code == 500) {
								layer.msg('系统错误：' + message);
							}
						}
					},
					"dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'table-bottom col-sm-10 col-xs-12 hidden-xs'i><'table-bottom col-xs-12 col-sm-10' p v>>",
					"columns": [
						//{"data" : "id", "defaultContent" : ""},
						{"data" : "question", "defaultContent" : ""},
						{"data" : "branch", "defaultContent" : ""},
						{"data" : "questionType", "defaultContent" : ""},
						{"data" : "startPatrolTime", "defaultContent" : ""},
						{"data" : "questionStatus", "defaultContent" : ""},
						{"data" : "createTime", "defaultContent" : ""},
						{"data" : "oversee", "defaultContent" : ""},
						{"data" : "overseeForm", "defaultContent" : ""}


					],
					"order": [[ 0, "asc" ]]
				} );
	}

	var progress;
	function progressInit(){
		progress =
				$('#progress').DataTable({
					"searching": false,
					"processing": false,
					"serverSide" : true,
					"ordering": false,
					"language": {
						"url": "/js/plugin/datatables/Chinese.lang"
					},
					"ajax": {
						"url" : "/questionRecords",
						"type":"get",
						"data":function(d){
							d.question = $('#question').val();
							d.questionKeyword = $("#questionKeyword option:selected").text();
							d.questionType = $("#questionType option:selected").text();
							d.questionStatus = $("#questionStatus option:selected").text();
							d.brancha = $("#brancha option:selected").text();
							d.branchb = $("#branchb option:selected").text();
						},
						"error":function(xhr, textStatus, errorThrown){
							var msg = xhr.responseText;
							console.log(msg);
							var response = JSON.parse(msg);
							var code = response.code;
							var message = response.message;
							if (code == 400) {
								layer.msg(message);
							} else if (code == 401) {
								localStorage.removeItem("token");
								layer.msg("token过期，请先登录", {shift: -1, time: 1000}, function(){
									location.href = '/login.html';
								});
							} else if (code == 403) {
								console.log("未授权:" + message);
								layer.msg('未授权');
							} else if (code == 500) {
								layer.msg('系统错误：' + message);
							}
						}
					},
					"dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'table-bottom col-sm-10 col-xs-12 hidden-xs'i><'table-bottom col-xs-12 col-sm-10' p v>>",
					"columns": [
						//{"data" : "id", "defaultContent" : ""},
						{"data" : "question", "defaultContent" : ""},
						{"data" : "branch", "defaultContent" : ""},
						{"data" : "questionType", "defaultContent" : ""},
						{"data" : "startPatrolTime", "defaultContent" : ""},



					],
					"order": [[ 0, "asc" ]]
				} );
	}


	// 下拉框可能会用到 New option
	// 这个里面的参数说明 第一个是显示的文本，第二个是value值
	// 例如：new Option(item.xm, item.id)第一个参数是下拉列表中显示的值  第二个参数是选中传递给后台的值
	layui.use(['form', 'upload', 'layer'],function(){
		var form = layui.form;
		$.ajax({
			url: '/mOverseeForms/getList',
			dataType: 'json',
			type: 'post',
			success: function (data) {
				//console.log(data);// 下面会提到这个data是什么值
				// 使用循环遍历，给下拉列表赋值
				$.each(data, function (index, value) {
					// console.log(value.department_id);
					$('#overseeForm').append(new Option(value.overseeStatus,value.id));// 下拉菜单里添加元素
				});
				layui.form.render("select");//重新渲染 固定写法
			}
		})

	});
	layui.use(['form', 'upload', 'layer'],function(){
		var form = layui.form;
		$.ajax({
			url: '/mQuestionKeywords/getList',
			dataType: 'json',
			type: 'post',
			success: function (data) {
				//console.log(data);// 下面会提到这个data是什么值
				// 使用循环遍历，给下拉列表赋值
				$.each(data, function (index, value) {
					// console.log(value.department_id);
					$('#questionKeyword').append(new Option(value.questionKeyword,value.id));// 下拉菜单里添加元素
				});
				layui.form.render("select");//重新渲染 固定写法
			}
		})
	});
	layui.use(['form', 'upload', 'layer'],function(){
		var form = layui.form;
		$.ajax({
			url: '/mQuestions/getList',
			dataType: 'json',
			type: 'post',
			success: function (data) {
				//console.log(data);// 下面会提到这个data是什么值
				// 使用循环遍历，给下拉列表赋值
				$.each(data, function (index, value) {
					// console.log(value.department_id);
					$('#questionType').append(new Option(value.question,value.id));// 下拉菜单里添加元素
				});
				layui.form.render("select");//重新渲染 固定写法
			}
		})
	});
	layui.use(['layer', 'form','jquery'], function () {
		var form = layui.form;
		$.ajax({
			url: '/branchs/getBranchs',
			dataType: 'json',
			type: 'post',
			data: {brandId:null},
			success: function (data) {
				//console.log(data);// 下面会提到这个data是什么值
				// 使用循环遍历，给下拉列表赋值
				$.each(data, function (index, value) {
					// console.log(value.department_id);
					$('#branch').append(new Option(value.branchName,value.id));// 下拉菜单里添加元素
				});
				layui.form.render("select");//重新渲染 固定写法



			}

		})
	});


	layui.use(['form','laydate'], function(){
		var laydate = layui.laydate;
		laydate.render({
			elem: '#startPatrolTime'
			,range: true,
			done: function (value, date, endDate) {

			}
		});

	});
	//监听提交

	layui.use(['form'], function () {
		var form = layui.form,
				layer = layui.layer,
				$ = layui.$;

		//监听提交
		form.on('submit(saveBtn)', function (data) {

			data.field.brancha = $("#brancha option:selected").text();//获取文本 id: 以降序排列此列
			data.field.branchb = $("#branchb option:selected").text();//获取文本
			data.field.questionKeyword = $("#questionKeyword option:selected").text();//获取文本
			data.field.questionType = $("#questionType option:selected").text();//获取文本
			data.field.overseeForm = $("#overseeForm option:selected").text();//获取文本
			console.log(JSON.stringify(data.field));

			$.ajax({
				type : 'POST',
				dataType: 'json',
				url : '/mOverseeQuestions/save',
				contentType: "application/json; charset=utf-8",
				data : JSON.stringify(data.field),
				success : function (res) {
					console.log(res);
					if(res.errorCode == 0){
						location.href = "mOverseeQuestionList.html";
					}

				}
			})
			return false;
		});

		//监听转至草稿箱
		form.on('submit(saveBtn2)', function (data) {

			data.field.brancha = $("#brancha option:selected").text();//获取文本 id: 以降序排列此列
			data.field.branchb = $("#branchb option:selected").text();//获取文本
			data.field.questionKeyword = $("#questionKeyword option:selected").text();//获取文本
			data.field.questionType = $("#questionType option:selected").text();//获取文本
			data.field.overseeForm = $("#overseeForm option:selected").text();//获取文本
			console.log(JSON.stringify(data.field));

			$.ajax({
				type : 'POST',
				dataType: 'json',
				url : '/mOverseeQuestions/saveDrafts',
				contentType: "application/json; charset=utf-8",
				data : JSON.stringify(data.field),
				success : function (res) {
					console.log(res);
					if(res.errorCode == 0){
						location.href = "mOverseeQuestionList.html";
					}

				}
			})
			return false;
		});



	});

layui.use('form',function () {
	var form = layui.form;
	form.render('select', 'scoreRuleForm')
})



	PanelInit()


</script>

